package com.cloud.edu.sys.service.impl;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cloud.edu.contants.Constant;
import com.cloud.edu.sys.dao.MenuMapper;
import com.cloud.edu.sys.dao.UserMapper;
//import com.cloud.edu.sys.dao.UserTokenMapper;
import com.cloud.edu.sys.model.Menu;
import com.cloud.edu.sys.model.MenuExample;
import com.cloud.edu.sys.model.User;
import com.cloud.edu.sys.service.ShiroService;
//import com.cloud.edu.sys.service.UserToken;


import java.util.*;

@Service
public class ShiroServiceImpl implements ShiroService {
    @Autowired
    private MenuMapper menuMapper;
    @Autowired
    private UserMapper userMapper;
//    @Autowired
//    private UserTokenMapper userTokenMapper;

    @Override
    public Set<String> getUserPermissions(String userId) {
        List<String> permsList;

        //系统管理员，拥有最高权限
        if(userId == Constant.SUPER_ADMIN){
        	MenuExample example =new MenuExample();
        	
            List<Menu> menuList = menuMapper.selectByExample(example);
            permsList = new ArrayList<>(menuList.size());
            for(Menu menu : menuList){
                permsList.add(menu.getPerms());
            }
        }
//        else{
////            permsList = sysUserDao.queryAllPerms(userId);
//        }
        //用户权限列表
        Set<String> permsSet = new HashSet<>();
//        for(String perms : permsList){
//            if(StringUtils.isBlank(perms)){
//                continue;
//            }
//            permsSet.addAll(Arrays.asList(perms.trim().split(",")));
//        }
        return permsSet;
    }

//    @Override
//    public UserToken queryByToken(String token) {
//        return userTokenMapper.selectByPrimaryKey(Long.valueOf(token));
//    }

    @Override
    public User queryUser(Long userId) {
        return userMapper.selectByPrimaryKey(userId);
    }

	
}
